#ifndef XGASYNCSLOT_H
#define XGASYNCSLOT_H

#include "XgSlot.h"
#include "XgMessagesProcessor.h"
#include "XgInvokeMessage.h"

/************************************************************************/
/* Class XgAsyncSlot (params: 1)                                        */
/************************************************************************/
template<typename P1 = NullClass>
class XgAsyncSlot : public XgSlot<P1>
{
public:
	typedef XgSlot<P1> Slot;

public:
	XgAsyncSlot( Slot* slot, XgMessagesProcessor* dstProcessor )
		: _slot(slot), _dstProcessor(dstProcessor)
	{
	}

public:
	void invoke(P1 p1)
	{
		XgInvokeMessage* msg = new XgInvokeMessage( _slot->prepare(p1) );
		_dstProcessor->postMessage(msg);
	}

private:
	Slot* _slot; 
	XgMessagesProcessor* _dstProcessor;
};

/************************************************************************/
/* Class XgAsyncSlot (params: 0)                                        */
/************************************************************************/
template<>
class XgAsyncSlot<NullClass> : public XgInvokable<void,NullClass>
{
public:
	typedef XgSlot<> Slot;

public:
	XgAsyncSlot( Slot* slot, XgMessagesProcessor* dstProcessor )
		: _slot(slot), _dstProcessor(dstProcessor)
	{
	}

public:
	void invoke()
	{
		XgInvokeMessage* msg = new XgInvokeMessage( _slot->prepare() );
		_dstProcessor->postMessage(msg);
	}

private:
	Slot* _slot; 
	XgMessagesProcessor* _dstProcessor;
};

#endif XGASYNCSLOT_H